dictA = {
  'name': 'Alex',
  'age': 18,
  'weight': '55kg'
}

# 获取 key
for key in dictA:
  print(key, end=' ')
  # name age weight

# 取 value
for value in dictA:
  print(value, end=' ^ ')
  # name ^ age ^ weight ^s

# 同时获取 key 和 value
for key in dictA:
  print(key, dictA[key], end=' ~ ')
  # name Alex ~ age 18 ~ weight 55kg ~ Alex 18

for key, value in dictA.items():
  print(key, value, end=', ')
  # name Alex, age 18, weight 55kg,

# 并行迭代
names = ['Alex', 'Rose', 'William']
ages = [18, 19, 20]
for index in range(len(names)):
  print(names[index], ages[index], end=', ')
  #  Alex 18, Rose 19, William 20,

# 反转序列迭代: 通过 reversed函数可以将一个序列反转
listA = ['清华大学', '北京大学', '其他大学']
reversedRes = reversed(listA)
for value in reversedRes:
  print(value, end=' # ')
  # 其他大学 # 北京大学 # 清华大学 #

# 压缩序列
for zipRes in zip(names, ages):
  print(zipRes, end='; ')
  # ('Alex', 18); ('Rose', 19); ('William', 20);